package com.fenghongzhang.day002;

import android.content.Context;
import android.content.SharedPreferences;

public class SPUtils {


    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    //1
    private SPUtils(){
        sharedPreferences = App.context.getSharedPreferences("a1902", Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }
    //2
    private static SPUtils spUtils = null;

    //3
    public static SPUtils getInstance(){
        if(spUtils == null){
            synchronized (SPUtils.class){
                if(spUtils == null){
                    spUtils = new SPUtils();
                }
            }
        }
        return spUtils;
    }


    public void put(String key,Object object){
        if(object instanceof String){
            editor.putString(key, (String) object);
        }else if(object instanceof Integer){
            editor.putInt(key, (Integer) object);
        }else if(object instanceof Long){
            editor.putLong(key, (Long) object);
        }else if(object instanceof Boolean){
            editor.putBoolean(key, (Boolean) object);
        }
        editor.commit();
    }




    public SharedPreferences getSharedPreferences() {
        return sharedPreferences;
    }

    public SharedPreferences.Editor getEditor() {
        return editor;
    }
}
